<?
//<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
require ("s_inc.php");
$rows = 20;
$page	  = $_REQUEST['page']?$_REQUEST['page']:1;
//權限
admin_main::pageChk('area_set');
?>
<?php require("s_head.tpl.php"); ?>
<?
$db_member = &new db($scfg['db']['member']);
$a1id     =  $_GET['a1id'];
$c1		  =  $db_member->rsArray("select * from `area_c1` where a1id= ? ",$a1id);
$table 	  = 'area_c2';
if($_POST)
{
	$act = $_POST['act'];
	if($act == 'modify')
	{
		//print_r($_POST);
		//更新
		$a2id = $_POST['a2id'];
		$a1id = $_POST['a1id'];
		$name = $_POST['name'];
		$taxis = $_POST['taxis'];
		$x = $_POST['x'];
		$y = $_POST['y'];
		$zip = $_POST['zip'];
		if(is_array($a2id))
		{
			foreach($a2id as $k=>$v)
			{
				$bind = array(
					'a2id'=>$a2id[$k],
					'name'=>$name[$k],
					'taxis'=>$taxis[$k],
					'x'=>$x[$k],
					'y'=>$y[$k],
					'zip'=>$zip[$k]
				);
				$db_member->update($table,$bind," a2id = ? ",$v);
			}
		}
		//刪除
		$del = $_POST['del'];
		if(is_array($del))
		{
			$db_member->delete("area_c2"," a2id in (?) ",$del);
		}
	}elseif($act == 'add')
	{
		if($_POST['name'])
		{
			$bind = array(
				'a1id'=>$_POST['a1id'],
				'name'=>$_POST['name'],
				'taxis'=>$_POST['taxis'],
				'x'=>$_POST['x'],
				'y'=>$_POST['y'],
				'zip'=>$_POST['zip']
			);
			$id = $db_member->insert($table,$bind);
			if($id)
			{
				echo g::msg("添加成功! ");
			}else
			{
				echo g::msg("失败,请重试! ");
			}
		}
	}
}
$rs = $db_member->dataArray("select * from {$table} where a1id=? order by a2id,taxis",$c1['a1id']);
//print_r($p);
?>
<form method="post">
<table width="100%"  border="0" cellpadding="4" cellspacing="1" class="tableoutline">
	<tr>
	<td colspan="6" class="tbhead">地區管理 -- <?=$c1['name']?></td>
  </tr>
  <tr class="_data_" style="font-weight:bold;">
	<td width="4%" align="right" style="color:#FF0000;">刪?</td>
	<td width="49%" align="left">地區名稱</td>
    <td width="17%" align="left">郵編</td>
    <td width="10%" align="left">排序</td>
    <td width="10%" align="left">經度(x)</td>
    <td width="10%" align="left">緯度(y)</td>
  </tr>
 <?
  	if(is_array($rs))
	{
		foreach($rs as &$v)
		{
?>
			<tr class="_data_">
			<input name="a2id[<?=$v['a2id']?>]" type="hidden" value="<?=$v['a2id']?>" />
			<input name="a1id[<?=$v['a2id']?>]" type="hidden" value="<?=$v['a1id']?>" />
			<td width="4%" align="right"><input type="checkbox" name="del[]" value="<?=$v['a2id']?>" /></td>
			<td align="left"><input name="name[<?=$v['a2id']?>]" type="text" value="<?=$v['name']?>" size="32" maxlength="32" />
			> <a href="_area3.php?a1id=<?=$v['a1id']?>&a2id=<?=$v['a2id']?>">进入路(街)口</a></td>
			<td align="left"><input name="zip[<?=$v['a2id']?>]" type="text" value="<?=$v['zip']?>" size="2" maxlength="10" /></td>
			<td align="left"><input name="taxis[<?=$v['a2id']?>]" type="text" value="<?=$v['taxis']?>" size="2" maxlength="10" /></td>
			<td align="left"><input name="x[<?=$v['a2id']?>]" type="text" value="<?=$v['x']?>" size="2" maxlength="10" /></td>
			<td align="left"><input name="y[<?=$v['a2id']?>]" type="text" value="<?=$v['y']?>" size="2" maxlength="10" /></td>
			</tr>
			<?
		}
	}

  ?>
 <tr class="_data_">
	<td>&nbsp;</td>
	<td colspan="5"><input name="Submit" type="submit" class="bginput" value="  送 出 " >
	<input name="Submit" type="reset" class="bginput" value=" 重 設 ">
	<input name="act" type="hidden" id="act" value="modify"></td>
  </tr>
</table>
</form>
  
 <hr />
<form name="addcats" method="post" onsubmit="return chk(this)">
<table width="100%" border="0" cellpadding="4" cellspacing="1" class="tableoutline">
        <tr>
        <td colspan="2" class="tbhead">添加地區名稱 -- <?=$c1['name']?> </td>
      </tr>
	  <tr class="_data_">
		<td align="right">所属地區：</td>
		<td align="left"> 
		 <input name="a1id" type="hidden" value="<?=$c1['a1id']?>" />
		<a href="_area.php"><?=$c1['name']?></a>
		 (必选)</td>
	  </tr>
	  <tr class="_data_">
		<td align="right">地區名稱：</td>
		<td align="left"> 
		 <input name="name" type="text" id="name" size="20" maxlength="32">
		 (必选)</td>
	  </tr>
	  <tr class="_data_">
        <td width="14%" align="right">郵編：        </td>
        <td width="86%" align="left"><input name="zip" type="text" id="zip" size="10" maxlength="10">
          (必选)</td>
      </tr>
      <tr class="_data_">
        <td align="right" valign="top">排序：</td>
        <td align="left"><input name="taxis" type="text" id="taxis" value="0" size="10" maxlength="10" />
          (可选)</td>
      </tr>
	  <tr class="_data_">
        <td align="right" valign="top">經度(x)：</td>
        <td align="left"><input name="x" type="text" id="x" size="10" maxlength="10" />
          (可选)</td>
      </tr>
	  <tr class="_data_">
        <td align="right" valign="top">緯度(y)：</td>
        <td align="left"><input name="y" type="text" id="y" size="10" maxlength="10" />
          (可选)</td>
      </tr>
      <tr class="_data_">
        <td>&nbsp;</td>
        <td><input type="submit" class="bginput" value="送出">
        <input type="reset" class="bginput" value="重設">
        <input name="act" type="hidden" id="act" value="add"></td>
      </tr>
</table>
</form>

<script language="JavaScript" type="text/JavaScript">
<!--
var chk = function(o)
{
	if(XypFrom.chk(o.name,'','请输入分類名稱!'))
	{
		return false;
	}else if(XypFrom.chk(o.taxis,'nums'))
	{
		return false;
	}else
	{
		return true;
	}
};
//---->
</script>
<? include("s_copyRight.tpl.php"); ?>